﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using Data;
using System.Transactions;



namespace DataView {
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        DataAcces da;
        public MainWindow() {
         
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
             da = new DataAcces();
             g.DataContext = da.getCLiente();
             dgm.DataContext = da.getFactura();
             }

        private void Button_Click(object sender, RoutedEventArgs e) {
            
            try {

               MessageBox.Show(da.checkConnection().ToString());

                using (TransactionScope scp = new TransactionScope()  ) {
                    
            CheckGrabo(  da.Grabar());
            CheckGrabo(da.Grabar2());


              scp.Complete();
            }
            
            } catch (Exception ex) {
                MessageBox.Show(ex.Message + ex.InnerException.Message);
            
            } 
          } 

        private void CheckGrabo(bool b){
            if (b == false) throw new Exception("No Grabó, hacemos rollback");
        }
    }
}
